home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11638 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  52 lines

  1. Newsgroups: comp.lang.c++
  2. Path: lade.news.pipex.net!pipex!insignia!franc
  3. From: William.Charnell@isltd.insignia.com (William Charnell)
  4. Subject: Re: C++ keyword
  5. Message-ID: <DoBAGv.IAz@isltd.insignia.com>
  6. Sender: news@isltd.insignia.com
  7. Nntp-Posting-Host: franc.isltd.insignia.com
  8. Organization: Insignia Solutions
  9. X-Newsreader: News Xpress 2.0 Beta #0
  10. References: <mwoods-1403961501550001@ou048057.otago.ac.nz>
  11. Date: Fri, 15 Mar 1996 13:58:24 GMT
  12.  
  13. In article <mwoods-1403961501550001@ou048057.otago.ac.nz>, mwoods@maths.otago.ac.nz (Matt B. Woods) wrote:
  14. >I am fairly new to C++ and I have just come across the keyword 'throw'. 
  15. >As I cannot find a reference to this keyword I assume I must be reading
  16. >the wrong books.  Can anyone tell me what 'throw' means?  Even better
  17. >could someone recommend a good complete reference to the C++ language?
  18.  
  19. The standard reference is Bjarne Stroustrup's "C++ reference manual" or 
  20. perhaps the annotated version (authored by Stroustrup and Margaret Ellis).
  21.  
  22. As regards "throw", it is to do with exception handling and is associated 
  23. with the "try" and "catch" keywords. The idea is that you can avoid having to 
  24. check whether functions return sensible values at various levels in a nested 
  25. sequence of function calls by wrapping the whole complex sequence at the 
  26. highest level in a "try" block with an appropriate "catch" exception handler 
  27. after it. Such as:
  28.  
  29. try
  30. {
  31.  <complex seqence> 
  32. }
  33. catch (<exception params>)
  34. {
  35.  <handler code>
  36. }
  37.  
  38. where any of the functions called in the <compex sequence> can say:
  39.  
  40. throw <exception params>
  41.  
  42. to abort the complex sequence and jump to the handler code (in the "catch" 
  43. block).
  44.  
  45. This is not a complete (or indeed completely accurate) account of exceptions 
  46. in C++. You are better off going to a good C++ text boot. Also excpetions 
  47. (like templates etc.) are not necessarily implemented by all C++ compilers.
  48.  
  49. Hope this helps
  50.  
  51. William Charnell
  52.